package com.david.learning.algorithm;

/**
 * Divide a big number to the product of some small Prime Number.
 * @author David Qi
 *
 */
public class DividePrime {

	public static void main(String[] args) {
		dividePrime2Factor(123456789, 2);
	}
	
	/**
	 *  So elegant!
	 * @param num : the big number
	 * @param factor : the small prime number
	 * @return prime number
	 */
	public static int dividePrime2Factor(int num, int factor){
		while(factor<num && num%factor!=0) factor ++;
		System.out.println(""+ factor);
		num = num/factor;
		if(factor >= num) return factor;
		return dividePrime2Factor(num, factor);
	}
}
